home *** CD-ROM | disk | FTP | other *** search
/ Computer Music Interactif…cial Edition 1999 Winter / cd 3.iso / mac / Mac / Shares / Midishare™1.68 / Development Tools / Sources Examples / Other MidiShare Examples / midiClock / MidiClock.c next >
Encoding:
C/C++ Source or Header  |  1992-06-05  |  1.6 KB  |  69 lines  |  [TEXT/MPS ]

  1. /*====================== A MIDI SHARE TOOL  (© GRAME 92) =====================
  2.  
  3. NAME
  4.       MidiClock -- a very simple MidiShare MPW tool
  5.  
  6. SYNOPSIS
  7.       MidiClock [-delay <d>] 
  8.           User type <q/Q> to quit
  9.  
  10. DESCRIPTION
  11.     "SendNote" open a MidiShare session, create and send a single note, and 
  12.     then close the MidiShare session
  13.  
  14. ===============================================================================*/
  15.  
  16.  
  17. #include <String.h>
  18. #include <StdLib.h>
  19. #include <Stdio.h>
  20. #include <MidiShare.h>
  21.  
  22.  
  23. #define nil     0
  24. #define true    1
  25. #define false    0
  26.  
  27.  
  28. //_______________________________________________________________________
  29. long lopt (char *argv[], char *name, long def)
  30. {
  31.     int    i;
  32.     for (i=0; argv[i]; i++) if (!strcmp(argv[i], name)) return atoi(argv[i+1]);
  33.     return def;
  34. }
  35.  
  36.  
  37. //_______________________________________________________________________
  38.  
  39. void wait(long d)
  40. {    d += MidiGetTime();
  41.     while (MidiGetTime() < d);
  42. }
  43.  
  44.  
  45. //_______________________________________________________________________
  46.  
  47. pascal void    Clocker (long date, short refNum, long delay, long a2, long a3)
  48. {
  49.     MidiSendIm (refNum, MidiNewEv(typeClock));
  50.     MidiCall (Clocker, date+delay, refNum, delay, a2, a3);
  51. }
  52.  
  53. //_______________________________________________________________________
  54.  
  55. main( int /*argc*/, char *argv[])
  56. {
  57.     short         ref;
  58.     char        c;
  59.     
  60.     ref = MidiOpen("\pMidiClock");                // open a MidiShare session
  61.     MidiConnect(ref, 0, true);                    // connect to physical Midi outputs
  62.     Clocker(MidiGetTime(), ref, lopt(argv, "-delay", 1), 0, 0);
  63.     
  64.     while ((c = getchar()) && c != 'q' && c != 'Q'); // wait user press Q or q
  65.     
  66.     MidiClose (ref);                            // close the MidiShare session
  67. }
  68.  
  69.